﻿using System;
using System.IO;
using System.Text;
using static System.Console;
/*写这个题三天，治好了蒟蒻的精神内耗,（人没了就内耗不起来了）*/
namespace chinese_character
{
    internal class Program
    {
        // public static string change_to_code(string chinese)
        // {
        //     string pCode = "";
        //     byte[] pArray = new byte[2];
        //     pArray = Encoding.Default.GetBytes(chinese);//得到汉字的字节数组
        //     int low = (short)(pArray[0] - '\0');//将字节数组的第一位160
        //     int high = (short)(pArray[1] - '\0') ;//将字节数组的第二位160
        //     pCode = low.ToString() + high.ToString();//再连接成字符串就组成汉字区位码
        //     return pCode;
        // }
        public static void show_character(string character)
        {
            {
                string all_code = "";
                string[] code = new string[16];

                for (int i = 0; i < character.Length; i++)
                {
                    byte[] array = Encoding.Default.GetBytes(character.Substring(i, 1)); //取出二进制编码内容

                    int lowcode = (short) (array[0] - 160);//低字节编码

                    int highcode = (short) (array[1] - 160);//高字节编码
                    
                    int b = (94 * (lowcode - 1) + (highcode - 1)) * 32;
                    FileStream fs = new FileStream("hzk16.dat", FileMode.Open, FileAccess.Read);
                    byte[] desBytes = new byte[fs.Length];
                    fs.Read(desBytes, 0, desBytes.Length);
                    //读取字模信息;
                    int x = 0;
                    for (int j = b; j < b + 32; x++)
                    {
                        code[x] = characterLength(Convert.ToString(desBytes[j], 2), 8) +
                                    characterLength(Convert.ToString(desBytes[j + 1], 2), 8);
                        all_code += characterLength(Convert.ToString(+desBytes[j], 16), 2) + " " +
                                   characterLength(Convert.ToString(+desBytes[j + 1], 16), 2) + " ";
                        j = j + 2;
                    }

                    for (int y = 0; y < code.Length; y++)
                    {
                        for (int y1 = 0; y1 < 16; y1++)
                        {
                            if (Convert.ToString(code[y][y1]) != "1")
                            {
                                Write("o");
                            }
                            else
                            {
                                ForegroundColor = ConsoleColor.Red;
                               Write("#");
                               ForegroundColor = ConsoleColor.Black;
                            }
                        }
                        WriteLine();
                    }

                    fs.Close();
                }

            }
        }

        public static string characterLength(string character, int len)
        {
            while (character.Length != len)
            {
                character = "0" + character;
            }

            return character;
        }
        public static void Main(string[] args)
        {
            string chara1 = "中";
            string chara2 = "国";
            show_character(chara1);
            WriteLine();
            show_character(chara2);
        }
    }
}